<template>
    <div class="container-common manage-student-type-in">
        <el-breadcrumb separator-class="el-icon-arrow-right">
            <el-breadcrumb-item>学生信息管理</el-breadcrumb-item>
            <el-breadcrumb-item>学生录入</el-breadcrumb-item>
        </el-breadcrumb>
        <el-row :gutter="100">
            <el-col :span="10" class=" manage-student-left">
                <el-form
                        ref="form"
                        :model="form"
                        class="form-container"
                        label-width="80px">
                    <el-form-item label="学号">
                        <el-input v-model="form.studentId" maxlength="200"></el-input>
                    </el-form-item>
                    <el-form-item label="姓名">
                        <el-input v-model="form.name" maxlength="200"></el-input>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click="handleSubmit">录入</el-button>
                    </el-form-item>
                </el-form>
            </el-col>
            <el-col :span="6">
                <el-upload
                        action="http://39.105.144.7:5002/api/import"
                        name="file"
                        :on-success="handleImport"
                        :show-file-list="false"
                        :data="otherImportData">
                    <el-button type="primary">批量录入</el-button>
                    <div slot="tip" class="el-upload__tip">请上传excel文件</div>
                </el-upload>
            </el-col>
        </el-row>

    </div>
</template>

<script>
    import Api from '@utils/api';
    import { mapGetters } from 'vuex';

    export default {
        name: "typeIn",
        data () {
            return {
                form: {
                    studentId: '',
                    name: ''
                }
            }
        },
        computed: {
            ...mapGetters([
                'getCurrentCourseId'
            ]),
            otherImportData () {
                return {
                    course_id: this.getCurrentCourseId
                }
            }
        },
        methods: {
            handleImport () {
                this.$notify({
                    title: '录入成功！',
                    type: 'success'
                });
            },
            handleSubmit () {
                Api({
                    method: 'post',
                    url: '/manageStudentAdd',
                    data: {
                        course_id: this.getCurrentCourseId,
                        student: this.form.studentId
                    }
                }).then(() => {
                    this.$notify({
                        type: 'success',
                        title: '添加成功！'
                    });
                })
            }
        }
    }
</script>

<style type="text/scss" lang="scss">
    .manage-student-type-in {
        .form-container {
            max-width: 400px;
            /*padding: 50px 50px 50px 20px;*/
        }
        .manage-student-left {
            border-right: 1px solid #eee;
        }
    }
</style>